#include <stdio.h>

void reverse_array(int *arr, int size)
{
  int start = 0;
  int end = size - 1;
  while (start < end)
  {
    // 交换元素
    int temp = arr[start];
    arr[start] = arr[end];
    arr[end] = temp;
    start++;
    end--;
  }
}

void reverse_array_by_pointer(int *arr, int size)
{
  int *start = arr;
  int *end = arr + size - 1;
  while (start < end)
  {
    // 交换元素
    int temp = *start;
    *start = *end;
    *end = temp;
    start++;
    end--;
  }
}
// 计算数组的平均值
int calculateAverage(int *arr, int size)
{
  int sum = 0;
  for (int i = 0; i < size; i++)
  {
    sum += *(arr + i); // 使用指针算术访问数组元素
  }
  return sum / size;
}

int main()
{
  int arr[] = {1, 2, 3, 4, 5};
  int size = sizeof(arr) / sizeof(arr[0]);

  printf("原始数组: ");
  for (int i = 0; i < size; i++)
  {
    printf("%d ", arr[i]);
  }
  printf("\n");

  reverse_array(arr, size);

  printf("反转后的数组: ");
  for (int i = 0; i < size; i++)
  {
    printf("%d ", arr[i]);
  }
  printf("\n");

  reverse_array_by_pointer(arr, size);

  printf("利用指针反转后的数组: ");
  for (int i = 0; i < size; i++)
  {
    printf("%d ", arr[i]);
  }
  printf("\n");

  int average = calculateAverage(arr, size);
  printf("数组的平均值: %d\n", average);

  return 0;
}